package de.acagamics.roteschlupfmuetze.core;

import java.io.Serializable;

import com.golden.gamedev.object.Sprite;

import de.acagamics.roteschlupfmuetze.RoteSchlupfmuetze;

public class LevelObject implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String name = "";
	private String zimage = "";
	private String image_inventory = "";
	private boolean clickable = false;
	private boolean visible = true;
	private int width = 140;
	private int height = 140;
	private String clickAction = "";

	private Sprite objectSprite  = new Sprite();

	public LevelObject() {
		/*if (!image.isEmpty()) {
			objectSprite = new Sprite(RoteSchlupfmuetze.loadImage(image));
		}else{
			objectSprite = new Sprite();
		}*/
	}
	
	public void wasLoaded() {
		setPosX(fromLevelX(getPosX()));
		setPosY(fromLevelY(getPosY()) - height);
	}

	public Sprite getObjectSprite() {
		return objectSprite;
	}

	public void setObjectSprite(Sprite objectSprite) {
		this.objectSprite = objectSprite;
	}

	public String getZimage() {
		return zimage;
	}

	public void setZimage(String image) {
		this.zimage = image;
		objectSprite.setImage(ImageHelper.scaleImage(RoteSchlupfmuetze.loadImage(image),width,height));
		this.width = objectSprite.getWidth();
		this.height = objectSprite.getHeight();
	}
	
	public void scaleImage(double factor) {
		this.width = (int)((double)this.width * factor);
		this.height = (int)((double)this.height * factor);
		objectSprite.setImage(ImageHelper.scaleImage(RoteSchlupfmuetze.loadImage(zimage),width,height));
	}

	public String getImage_inventory() {
		return image_inventory;
	}

	public void setImage_inventory(String image_inventory) {
		this.image_inventory = image_inventory;
	}


	public boolean isClickable() {
		return clickable;
	}

	public void setClickable(boolean clickable) {
		this.clickable = clickable;
	}

	public boolean isVisible() {
		return visible;
	}

	public void setVisible(boolean visible) {
		this.visible = visible;
		this.objectSprite.setImmutable(visible);
		this.objectSprite.setActive(visible);
	}

	public int getPosX() {
		return (int)objectSprite.getX();
	}

	public void setPosX(int posX) {
		objectSprite.forceX(posX);
	}

	public int getPosY() {
		return (int)objectSprite.getY();
	}

	public void setPosY(int posY) {
		objectSprite.forceY(posY);
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public String getClickAction() {
		return clickAction;
	}

	public void setClickAction(String clickAction) {
		this.clickAction = clickAction;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	private int fromLevelX(int x) {
		return Level.currentLevelData.fromLevelX(x);
	}
	
	private int fromLevelY(int y) {
		return Level.currentLevelData.fromLevelY(y);
	}
}
